<?php
/**
 * 
 * @author yuxun
 *
 */

class RoleInfoService extends Service {

	public static function indexHeader($params){
		$header = array(
				'RoleName'       => array('text' => '角色名'),
				'CreateTime'     => array('text' => '创角时间'),
				'SumPayMoney'    => array('text' => '累计充值','rule' => 'numeric'),		
		);
		
		if(isset($params['open_time'])){
			$open_time = $params['open_time'];
			$seven_open_time = $params['seven_open_time'];
			$open_time_int = strtotime($open_time);
			$seven_open_time_int = strtotime($seven_open_time);
			$i = 1;
			while($open_time_int  <= $seven_open_time_int){
				$day = date('Y-m-d',$open_time_int);
				$open_time_int = strtotime('+1 day', $open_time_int);
					
				$everyDay = array();
				$everyDay['OnlineTime_'.$day] = array('text' => '在线时长(分钟)', 'rule' => 'numeric');
				$everyDay['Level_'.$day]       = array('text' => '等级', 'rule' => 'numeric');
				$everyDay['IsLogin_'.$day]     = array('text' => '是否登录');
				$everyDay['guildName_'.$day]   = array('text' => '帮会名称');
				$everyDay['PayMoney_'.$day]    = array('text' => '充值金额','rule' => 'numeric');
				$header['day_'.$day]          = array('text' => '开服第'.$i.'天('.$day.')', 'include' => $everyDay);
				$i++;
			}
		}
		
		return $header;
	}
	

	
	public static function indexData($params){

		if(!isset($params['open_time'])){ //开服时间不存在
			return array();
		}

		$modRoleInfo = new ModSevenRoleInfo();
		$result = $modRoleInfo->select($params);
		
        $list_one = array();
		foreach($result as $key=>$val){
			$list_one[$val['RoleId']][$val['RecDate']] = $val;
		}

		
		$list_two = array();
		foreach ($list_one as $key=>$val){			
			$SumPayMoney = 0;
			$i = 1;
			foreach ($val as $k=>$v){
				$list_two[$key]['RoleName'] = $v['RoleName'];
				$SumPayMoney += $v['PayMoney'];
				if(isset($v['CreateTime'])){  
					$CreateTime = date('Y-m-d H:i:s',$v['CreateTime']);
					$list_two[$key]['CreateTime'] = $CreateTime;
				}
				
				$list_two[$key]['OnlineTime_'.$k] = isset($v['OnlineTime'])?  number_format($v['OnlineTime'] / 60, 2) : '0';  //在线时长
				$list_two[$key]['Level_'.$k] = isset($v['Level'])?  $v['Level'] : '0';  //等级
				$list_two[$key]['IsLogin_'.$k] = $v['IsLogin'] == 1?  '是' : '否';  //是否登录
				$list_two[$key]['guildName_'.$k] = isset($v['guildName'])?  $v['guildName'] : '';  //帮会名称
				$list_two[$key]['PayMoney_'.$k] = isset($v['PayMoney'])?  $v['PayMoney'] : '0';  //帮会名称
			}
			$list_two[$key]['SumPayMoney'] = $SumPayMoney;
		}
		
// 		echo '<pre/>';
// 		var_dump($list_one);exit;

		return $list_two;
	}
	
	
} 